import service from '@/api/service'
import type { DashboardCardVo, DashboardLayoutVo } from '@/type/Dashboard'
import type { Page, PageQuery } from '@/type/common/list-types'

const mapping = 'dashboard'

// 卡片管理接口

/** 获取所有卡片 */
export const getAllDashboardCardsApi = () => service.get<DashboardCardVo[]>(`${mapping}/card/list`)

/** 条件分页查询卡片列表 */
export const dashboardCardListApi = (pageQuery: PageQuery) =>
  service.post<Page<DashboardCardVo>>(`${mapping}/card/page`, pageQuery)

/** 根据卡片ID查询卡片详细信息 */
export const dashboardCardInfoApi = (id: string) => service.get<DashboardCardVo>(`${mapping}/card/${id}`)

/** 保存卡片信息 */
export const saveDashboardCardApi = (cardInfo: DashboardCardVo) => service.put(`${mapping}/card`, cardInfo)

/** 新增卡片 */
export const addDashboardCardApi = (cardInfo: DashboardCardVo) => service.post(`${mapping}/card`, cardInfo)

/** 更新卡片 */
export const updateDashboardCardApi = (id: string, cardInfo: DashboardCardVo) => service.put(`${mapping}/card/${id}`, cardInfo)

/** 删除卡片 */
export const deleteDashboardCardApi = (id: string) => service.delete(`${mapping}/card/${id}`)

// 布局管理接口

/** 获取用户布局 */
export const getUserDashboardLayoutApi = (userId: string) => service.get<DashboardLayoutVo>(`${mapping}/layout/user/${userId}`)

/** 保存布局信息 */
export const saveDashboardLayoutApi = (layoutInfo: DashboardLayoutVo) => service.put(`${mapping}/layout`, layoutInfo)